//
// Created by linfe on 2023/5/14.
//

#ifndef H750_BSP_COMM_PROTOCOL_H
#define H750_BSP_COMM_PROTOCOL_H

#define _1_PACKED __attribute__ ((packed))
#define _4_PACKED __attribute__ ((aligned (4)))
#define SYNC_MAX_MSG_LENGTH 256
#define MSG_ID(set, id) (set << 16u) | (id & 0xff)
#define COMM_SYNC_HEADER   0XAA55AA55L
#define COMM_SYNC_END_MARK 0XAA66AA66L

#include "stdint.h"




#define COMM_SYNC_MSG_DEF(set, id, name, fmt) \
typedef struct  {                            \
uint32_t header;                              \
uint32_t msg_id ;                             \
uint64_t timestamp;             \
uint32_t length;                \
struct fmt  data;                 \
uint32_t check_sum;             \
uint32_t end_mark;              \
} comm_sync_msg_##name##_t ;     \
enum{comm_sync_msg_##name##_id = MSG_ID(set,id)};

#define PACK_DATA(__D) \
{                      \
   __D                    \
}

#define CREATE_COMM_SYNC_MSG(name, pack_data) \
{                                  \
    .header = COMM_SYNC_HEADER,    \
    .msg_id = comm_sync_msg_##name##_id,\
    .length = sizeof(comm_sync_msg_##name##_t), \
    .data = pack_data,             \
    .end_mark = COMM_SYNC_END_MARK,\
}

#define COMM_SYNC_SET_POSE 0x01

#define COMM_SYNC_SET_SENSOR 0x02

#pragma pack(4)
COMM_SYNC_MSG_DEF(COMM_SYNC_SET_POSE, 0x15, atti,
                  { float q[4]; }
)
COMM_SYNC_MSG_DEF(COMM_SYNC_SET_POSE, 0x16, pose,
                  {
                      double latlon[2];
                      float height;
                      float pos_std;
                  })
COMM_SYNC_MSG_DEF(COMM_SYNC_SET_POSE, 0x17, pos_atti,
                  { float q[4]; }
)

COMM_SYNC_MSG_DEF(COMM_SYNC_SET_SENSOR, 0x18, imu,
                  {
                      float acce[3];
                      float gyro[3];
                  }
)
typedef struct  {
    uint32_t header;
    uint32_t msg_id;
    uint64_t timestamp;
    uint32_t length;
    uint32_t data;
    uint32_t check_sum;
    uint32_t end_mark;
} sync_msg_t;
#pragma pack()
#endif //H750_BSP_COMM_PROTOCOL_H
